package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ruoyi.mes.vo.list.ProTecListVo;
import com.ruoyi.mes.vo.product.ProTecVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProTec;
import com.ruoyi.mes.service.IProTecService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品工艺Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "产品工艺")
@RestController
@RequestMapping("/mes/tec")
public class ProTecController extends BaseController {
    @Autowired
    private IProTecService proTecService;

    /**
     * 查询产品工艺列表
     */
    @ApiOperation(value = "查询产品工艺列表")
    @PreAuthorize("@ss.hasPermi('mes:tec:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProTec proTec) {
        startPage();
        List<ProTec> list = proTecService.selectProTecList(proTec);
        return getDataTable(list);
    }

    /**
     * 导出产品工艺列表
     */
    @ApiOperation(value = "导出产品工艺列表")
    @PreAuthorize("@ss.hasPermi('mes:tec:export')")
    @Log(title = "产品工艺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProTec proTec) {
        List<ProTec> list = proTecService.selectProTecList(proTec);
        ExcelUtil<ProTec> util = new ExcelUtil<ProTec>(ProTec.class);
        util.exportExcel(response, list, "产品工艺数据");
    }

    /**
     * 获取产品工艺详细信息
     */
    @ApiOperation(value = "获取产品工艺详细信息")
    @PreAuthorize("@ss.hasPermi('mes:tec:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proTecService.selectProTecById(id));
    }

    /**
     * 新增产品工艺
     */
    @PreAuthorize("@ss.hasPermi('mes:tec:add')")
    @Log(title = "产品工艺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProTec proTec) {
        return toAjax(proTecService.insertProTec(proTec));
    }

    /**
     * 修改产品工艺
     */
    @ApiOperation(value = "修改产品工艺")
    @PreAuthorize("@ss.hasPermi('mes:tec:edit')")
    @Log(title = "产品工艺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProTec proTec) {
        return toAjax(proTecService.updateProTec(proTec));
    }

    /**
     * 删除产品工艺
     */
    @ApiOperation(value = "删除产品工艺")
    @PreAuthorize("@ss.hasPermi('mes:tec:remove')")
    @Log(title = "产品工艺", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proTecService.deleteProTecByIds(ids));
    }


    //*******************************************************
    /**
     * 增-工艺
     * @param proTecVo
     * @return
     */
    @ApiOperation(value = "新增工艺")
    @PostMapping("/savetec")
    public AjaxResult savetec(@RequestBody ProTecVo proTecVo){
        return proTecService.savetec(proTecVo);
    }

    /**
     * 改-工艺
     * @param proTecVo
     * @return
     */
    @PutMapping("/edittec")
    public AjaxResult edittec(@RequestBody ProTecVo proTecVo){
        return proTecService.edittec(proTecVo);
    }

    /**
     * 删-工艺-工艺编码
     * @param tecCode
     * @return
     */
    @DeleteMapping("/deleteProTec")
    public AjaxResult deleteProTec(@RequestParam String tecCode){
        return toAjax(proTecService.deleteProTec(tecCode));
    }

    /**
     * 查 -工艺详情
     * @param id
     * @return
     */
    @GetMapping("/getDetals")
    public AjaxResult getDetals(@RequestParam Long id){
        return success(proTecService.getDetals(id));
    }


    /**
     * 查-工艺分页
     * @param proTecListVo
     * @return
     */
    @GetMapping("/proTecList")
    public TableDataInfo proTecList(ProTecListVo proTecListVo){
        startPage();
        List<ProTecListVo> proTecListVos = proTecService.selectProTecVoList(proTecListVo);
        return getDataTable(proTecListVos);
    }


}
